﻿using System;
using System.IO;

// Token: 0x02000321 RID: 801
public static class PNG_Loader
{
	// Token: 0x06001433 RID: 5171 RVA: 0x0008DEBC File Offset: 0x0008C0BC
	public static byte[] Load(BinaryReader reader)
	{
		byte[] array = new byte[8];
		byte[] array2 = new byte[]
		{
			137,
			80,
			78,
			71,
			13,
			10,
			26,
			10
		};
		array = reader.ReadBytes(8);
		for (int i = 0; i < 8; i++)
		{
			if (array[i] != array2[i])
			{
				reader.BaseStream.Seek(0L, SeekOrigin.Begin);
				return null;
			}
		}
		string a;
		do
		{
			int num = reader.ReadInt32();
			num = PNG_Loader.RevEndian(num);
			char[] value = new char[4];
			value = reader.ReadChars(4);
			byte[] array3 = reader.ReadBytes(num);
			int num2 = reader.ReadInt32();
			a = new string(value);
		}
		while (!(a == "IEND"));
		long position = reader.BaseStream.Position;
		reader.BaseStream.Seek(0L, SeekOrigin.Begin);
		if (position > 0L)
		{
			return reader.ReadBytes((int)position);
		}
		return null;
	}

	// Token: 0x06001434 RID: 5172 RVA: 0x0008DFA0 File Offset: 0x0008C1A0
	public static long CheckSize(BinaryReader reader)
	{
		byte[] array = new byte[8];
		byte[] array2 = new byte[]
		{
			137,
			80,
			78,
			71,
			13,
			10,
			26,
			10
		};
		array = reader.ReadBytes(8);
		for (int i = 0; i < 8; i++)
		{
			if (array[i] != array2[i])
			{
				reader.BaseStream.Seek(0L, SeekOrigin.Begin);
				return 0L;
			}
		}
		string a;
		do
		{
			int num = reader.ReadInt32();
			num = PNG_Loader.RevEndian(num);
			char[] value = new char[4];
			value = reader.ReadChars(4);
			byte[] array3 = reader.ReadBytes(num);
			int num2 = reader.ReadInt32();
			a = new string(value);
		}
		while (!(a == "IEND"));
		long position = reader.BaseStream.Position;
		reader.BaseStream.Seek(0L, SeekOrigin.Begin);
		return position;
	}

	// Token: 0x06001435 RID: 5173 RVA: 0x0008E074 File Offset: 0x0008C274
	public static long CheckSize(byte[] data)
	{
		long result = 0L;
		using (MemoryStream memoryStream = new MemoryStream(data))
		{
			using (BinaryReader binaryReader = new BinaryReader(memoryStream))
			{
				result = PNG_Loader.CheckSize(binaryReader);
			}
		}
		return result;
	}

	// Token: 0x06001436 RID: 5174 RVA: 0x0008E0DC File Offset: 0x0008C2DC
	private static int RevEndian(int val)
	{
		byte[] bytes = BitConverter.GetBytes(val);
		Array.Reverse(bytes);
		return BitConverter.ToInt32(bytes, 0);
	}
}
